package com.cmcc.pp.api;

import com.zrspring.libv2.util.JsonUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by shopping on 2017/12/22 14:35.
 * https://github.com/wheroj
 */

public class ParamTools {

    private final JSONObject params;
    private final JSONObject jsonObject;

    public ParamTools() {
        params = new JSONObject();
        jsonObject = new JSONObject();
        try {
            params.put("userId", "65");
            params.put("calltype", "2");
            params.put("orgGroupCode", "ALL");
            params.put("version", "2.10.1");

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            params.put("submitTime", dateFormat.format(new Date()));
            params.put("isReport", "Y");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void addParam(String name, Object value) {
        try {
            params.put(name, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void remove(String name) {
        params.remove(name);
    }

    public String getParam() {
        try {
            jsonObject.put("param", DesUtil.encrypt(params.toString()));
            return jsonObject.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
